﻿using System.Collections.Generic;
using Lucid.ESA.ClientDataSystem.Domain.Common;

namespace Lucid.ESA.ClientDataSystem.Domain.Entities
{
    public class Client : Entity
    {
        protected string _name;
        protected bool _deleted;
        protected IList<Contact> _contacts;
        protected IList<Site> _sites;

        public virtual string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public virtual bool Deleted
        {
            get { return _deleted; }
            set { _deleted = value; }
        }

        public virtual IList<Contact> Contacts
        {
            get { return _contacts; }
            set { _contacts = value; }
        }

        public virtual IList<Site> Sites
        {
            get { return _sites; }
            set { _sites = value; }
        }

        public static Client Create(string name)
        {
            Client client = new Client();
            client.Name = name;
            client.Deleted = false;
            client.Contacts = new List<Contact>();
            client.Sites = new List<Site>();
            return client;
        }

        public virtual void Edit(string name)
        {
            _name = name;
        }

        public virtual void Delete()
        {
            _deleted = true;
        }

        public virtual ValidationMessageCollection Validate()
        {
            ValidationMessageCollection messages = new ValidationMessageCollection();

            //Name is required.
            if (_name == null || _name == string.Empty)
                messages.AddError("Name", "Name cannot be empty.");

            //Name cannot be more than 30 characters.
            if (_name != null && _name.Length > 30)
                messages.AddError("Name", "Name cannot be longer than 30 characters.");

            return messages;
        }
    }
}
